package com.hancher.common.rv;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.viewbinding.ViewBinding;

import com.chad.library.adapter4.BaseQuickAdapter;
import com.hancher.common.androidutil.LogUtil;
import com.hancher.common.javautil.GsonUtil;

/**
 * 描述 : viewbinding adapter <br/>
 * 时间 : 2023/11/23 19:39 <br/>
 * 作者 : Hancher ytu_shaoweijie@163.com
 */
public abstract class BaseVBAdapter<VB extends ViewBinding, T> extends BaseQuickAdapter<T, BaseVBViewHolder<VB>> {

    @Override
    protected void onBindViewHolder(@NonNull BaseVBViewHolder<VB> viewHolder, int position, @Nullable T item) {
        LogUtil.v("item " + GsonUtil.obj2JsonStr(item));
        convertItem(viewHolder.getBinding(), position, item);
    }

    protected abstract VB createViewBinding(LayoutInflater from, ViewGroup viewGroup);

    protected abstract void convertItem(VB binding, int position, T item);

    @NonNull
    @Override
    protected BaseVBViewHolder<VB> onCreateViewHolder(@NonNull Context context, @NonNull ViewGroup viewGroup, int position) {
        return new BaseVBViewHolder<>(createViewBinding(LayoutInflater.from(context), viewGroup));
    }


}
